package com.OrderingServer.config;
import com.OrderingServer.interceptor.AuthInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Web配置类
 * 用于注册拦截器，并配置拦截规则
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    // 注入权限拦截器
    @Autowired
    private AuthInterceptor authInterceptor;

    /**
     * 注册拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册权限拦截器
        registry.addInterceptor(authInterceptor)
                // 配置拦截所有路径
                .addPathPatterns("/**")
                // 配置不拦截的路径（登录、注册接口不需要登录即可访问）
                .excludePathPatterns(
                        "/user/login",    // 登录接口
                        "/user/register" , // 注册接口
                        "/sell/**",
                        "/api/**"
                );
    }
}
    